//
// Created by castle on 2020/9/10.
//

#ifndef GAMELOGIC_H
#define GAMELOGIC_H

#include <cstdint>
#include <iostream>

class GameLogic
{
public:
	enum CellType:uint8_t { Free = 0, Player1 = 1, Player2 = 2};
	enum GameStatue:uint8_t { Playing = 0, Player1Win = 1, Player2Win = 2, Draw = 3};
private:
	CellType cells[9]{};
	GameStatue StatueCheck();
	int step;
public:
	GameLogic();
	inline int GetCellIndex(int x, int y) const
	{
		int index = x - 1 + (y - 1) * 3;
		if(index < 0 | index > 8)
			throw  "x must in range(1, 3), y must in range(1, 3)";
		return index;
	}
	inline int GetPlayerNow() { return step % 2 + 1; }
	GameStatue PickCell(int index);
	inline GameStatue PickCell(int x, int y) { return PickCell(GetCellIndex(x, y)); }
	inline CellType GetCell(int index) const { return cells[index]; }
	inline CellType GetCell(int i, int j) const { return cells[GetCellIndex(i, j)]; }
	inline const CellType* GetCells() const { return cells; }
};


#endif //GAMELOGIC_H
